package com.three.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.three.entity.Crollcall;
import com.three.service.CrollcallService;
import com.three.util.JPushUtil;

@Controller
@RequestMapping("/crollcall")
public class CrollcallController {

	@Autowired
	CrollcallService crollcallService;
	private static Logger logger = Logger.getLogger(CrollcallController.class); 
	
	@RequestMapping("/findCrollcalls")
	@ResponseBody
	public List<Crollcall> findCrollcalls(Integer cid) {
		return crollcallService.findCrollcallsByCid(cid);
	} 
	
	@RequestMapping("/createCrollcalls")
	@ResponseBody
	public void createCrollcalls(Integer cid,
			String name,
			String date,
			HttpServletResponse response) throws IOException {
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String result = crollcallService.createCrollcalls(cid, name, date);
		out.write(result);
		out.close();
		JPushUtil.createPushRollcallMsg(String.valueOf(cid),
				"点击通知验证考勤码以完成签到", "【课堂派】您有一条考勤通知");
	} 
	
	@RequestMapping("/stopRollcall")
	@ResponseBody
	public void stopRollcall(Integer cid,
			String rollcallName,
			Integer attendance,
			Integer miss,
			PrintWriter out) {
		String result = crollcallService.stopRollcall(
				cid, rollcallName, attendance, miss);
		out.write(result);
		out.close();
	} 
	
}
